#include "webdialog.h"
#include "qwebview.h"
#include "qboxlayout.h"
#include "qwebframe.h"
#include "qdebug.h"

WebDialog::WebDialog(WebHost *webHost, QString url): WebHost(webHost) {

	QDialog* dialog = new QDialog(webHost->getParentWindow());
	QWebView* webView = new QWebView(dialog);
	webView->setPage(this->webPage);
	//qDebug() << url;
	//this->webPage->mainFrame()->load(QUrl(url));

	QHBoxLayout *horizontalLayout = new QHBoxLayout;
	horizontalLayout->setContentsMargins(0, 0, 0, 0);
	horizontalLayout->addWidget(webView);
	dialog->setLayout(horizontalLayout);

	QPalette palette = webView->palette();
	palette.setBrush(QPalette::Base, Qt::transparent);
	webView->setPalette(palette);
	webView->setAttribute(Qt::WA_OpaquePaintEvent, false);

	if (dialog->parent()) {
		dialog->open();
	} else dialog->exec();

	//this->deleteLater();

}

WebDialog::~WebDialog() {
	qDebug() << "WebDialog::~WebDialog";
}
